<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>





  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

  <script>
               

   var tasks=[
              'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/queryOneReport',
              'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/queryAreaDeviceSon',
              'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/queryAreaDeviceParent',
               'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/authLogin',
              'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/serviceSecod',
              'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/getDetailsText',
              'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/Hastasksdata',
              'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/taskAgentsUrl',
              'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/query',
              'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/proxy',
              'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/queryAreaDeviceSon',
              'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/queryAreaDeviceParent',
              'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/authLogin',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/serviceSecod',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/getDetailsText',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/Hastasksdata',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/taskAgentsUrl',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/query',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/proxy',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/queryAreaDeviceSon',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/queryAreaDeviceParent',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/authLogin',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/serviceSecod',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/getDetailsText',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/Hastasksdata',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/taskAgentsUrl',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/query',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/proxy',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/queryAreaDeviceSon',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/queryAreaDeviceParent',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/authLogin',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/serviceSecod',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/getDetailsText',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/Hastasksdata',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/taskAgentsUrl',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/query',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/proxy',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/queryAreaDeviceSon',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/queryAreaDeviceParent',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/authLogin',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/serviceSecod',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/getDetailsText',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/Hastasksdata',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/taskAgentsUrl',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/query',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/proxy',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/queryAreaDeviceSon',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/queryAreaDeviceParent',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/authLogin',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/serviceSecod',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/getDetailsText',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/Hastasksdata',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/taskAgentsUrl',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/query',
            //   'https://mock.mengxuegu.com/mock/606586ca987c3024c3ba1c3e/example/proxy',
   ]

    function multiRequest(urls = [], maxNum) {
         let lenNum=urls.length;
         let counter=0;
         let results=[]

        return new Promise((resolve,reject)=>{
            while(counter<maxNum){
                start()
            }
            console.log('counter'+counter)
            function start(){
                console.log('xxxxxxxxxxxx')
                if(counter>=lenNum){
                    resolve(results)
                    return
                }
                let current=counter++
                let url=urls[current]
                axios.get(url).then((res)=>{
                    results[current]=res.data.data
                    start()
                }).catch((err)=>{
                    results[current]=err
                    start()
                })
            }
            
        })
         
    }

     multiRequest(tasks,4).then(result =>{
          // console.log('成功'+result)
          console.log( result )
     }).catch(reason =>{
           console.log('失败'+reason)
     })

    // let aa=0
    // function fm(){
    //     aa++   
    //     console.log('aaaaaaa')
    // }
    // while(aa<5){
    //     fm()
    // }

      
    


  </script>

</body>

</html>